package com.ml.model;

import org.hibernate.annotations.GenericGenerator;

import javax.persistence.*;
import javax.servlet.http.HttpServletRequest;
import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.Date;

@Entity
@Table(name = "ml_log", schema = "")
/**自定义的日志又来记录一些东西*/
public class MLlog implements Serializable {


    /**32位 唯一标识*/
    private String id;

    private String url;

   // private String host;

    private String user_ip;

    private String createTime;

    private String title;

    private String content;

    /**日志类型 0 正常日志 1 异常日志*/
    private Integer type;

    public MLlog(){

    }

    public MLlog(String title,String content){
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        this.createTime = sdf.format(new Date());
        this.title = title;
        this.content = content;
    }

    public MLlog(String url,String title,String content){
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        this.createTime = sdf.format(new Date());
        this.url = url;
        this.title = title;
        this.content = content;
    }

    public MLlog(int type,String url,String title,String content){
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        this.createTime = sdf.format(new Date());
        this.type = type;
        this.url = url;
        this.title = title;
        this.content = content;
    }

    public MLlog(int type,String url,String title,String content,String user_ip){
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        this.createTime = sdf.format(new Date());
        this.type = type;
        this.url = url;
        this.title = title;
        this.content = content;
        this.user_ip = user_ip;
    }

    public MLlog(int type,String title,String content,HttpServletRequest request){
        this.type = type;
        this.title = title;
        this.content = content;
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        this.createTime = sdf.format(new Date());
        this.url = request.getRequestURI();
        this.user_ip = request.getRemoteAddr();
        //this.host = request.getRemoteHost();
    }


    @Id
    @GeneratedValue(generator = "uuid")
    @GenericGenerator(name = "uuid", strategy = "uuid")
    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    @Column(name = "createtime")
    public String getCreateTime() {
        return createTime;
    }

    public void setCreateTime(String createTime) {
        this.createTime = createTime;
    }

    @Column(name = "title")
    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    @Column(name = "content")
    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    @Column(name = "url")
    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    @Column(name = "type")
    public Integer getType() {
        return type;
    }

    public void setType(Integer type) {
        this.type = type;
    }

   /* @Column(name = "host")
    public String getHost() {
        return host;
    }

    public void setHost(String host) {
        this.host = host;
    }
*/
    @Column(name = "user_ip")
    public String getUser_ip() {
        return user_ip;
    }

    public void setUser_ip(String user_ip) {
        this.user_ip = user_ip;
    }
}
